package com.atguigu.gulimall.search.controller;

import com.atguigu.gulimall.search.service.MallSearchSearchService;
import com.atguigu.gulimall.search.vo.SearchParams;
import com.atguigu.gulimall.search.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class WebSearchController {
    @Autowired
    MallSearchSearchService mallSearchSearchService;

    @GetMapping("/list.html")
    public String toSearchPage(SearchParams searchParams, Model model, HttpServletRequest request){
        searchParams.set_queryString(request.getQueryString()); //_queryString是个字段
        SearchResultVo searchResult =  mallSearchSearchService.getSearchResult(searchParams);
        model.addAttribute("result",searchResult);
        return "list";
    }
}
